<template>
  <div>
    <div class="action-bar">
      <el-button type="primary" size="mini" icon="el-icon-plus" @click="add">新建</el-button>
    </div>
    <FormDialog class="fixed-dialog-height" width="90%" title="新建" :show="dialogFormVisible" @on-ok="ok" @on-cancel="cancel">
      <EditForm ref="editForm" />
    </FormDialog>
  </div>
</template>

<script>
import FormDialog from '@neu/biz-core/components/FormDialog'
// 编辑实例组件独立编写，需要传递id属性，判断新建还是更新操作
import EditForm from './editForm'

export default {
  name: 'PermissionsActionBar',
  components: {
    FormDialog,
    EditForm
  },
  data() {
    return {
      dialogFormVisible: false
    }
  },
  created() {
  },
  methods: {
    // 新建用户按钮点击处理
    add() {
      this.dialogFormVisible = true
    },
    // 创建用户对话框确认事件处理
    ok() {
      // 直接调用表单实例的保存方法
      this.$refs.editForm.save().then(response => {
        if (response === false) return
        this.$message({
          showClose: true,
          message: '操作成功！',
          type: 'success'
        })
        // 调用pageable-table实例的mixin方法refresh()，更新表格
        this.$parent.refresh()
        // 关闭对话框
        this.$refs.editForm.reset()
        this.dialogFormVisible = false
      })
    },
    cancel() {
      this.$refs.editForm.reset()
      this.dialogFormVisible = false
    }
  }
}
</script>
